package com.kexio.email.enums;

/**
 * 邮件发送状态枚举
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public enum EmailStatus {
    
    /**
     * 待发送
     */
    PENDING("pending", "待发送"),
    
    /**
     * 发送中
     */
    SENDING("sending", "发送中"),
    
    /**
     * 发送成功
     */
    SUCCESS("success", "发送成功"),
    
    /**
     * 发送失败
     */
    FAILED("failed", "发送失败"),
    
    /**
     * 重试中
     */
    RETRYING("retrying", "重试中"),
    
    /**
     * 已取消
     */
    CANCELLED("cancelled", "已取消"),
    
    /**
     * 已过期
     */
    EXPIRED("expired", "已过期");
    
    private final String code;
    private final String description;
    
    EmailStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 根据代码获取枚举
     */
    public static EmailStatus fromCode(String code) {
        for (EmailStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown email status code: " + code);
    }
    
    /**
     * 是否为最终状态 (不会再变化)
     */
    public boolean isFinalStatus() {
        return this == SUCCESS || this == FAILED || this == CANCELLED || this == EXPIRED;
    }
    
    /**
     * 是否可以重试
     */
    public boolean canRetry() {
        return this == FAILED || this == RETRYING;
    }
}
